var utils ={
		loadJs:function(url){
			var script = document.createElement("script");
			script.type = "text/javascript";
			script.src = url;
			document.head.appendChild(script);
		},
		date:new Date(),
		clearCookie: function(name) {
	        this.setCookie(name, "", -1)
	    },
		setCookie: function(name, value, seconds) {
	        seconds = seconds || 0;
	        var expires = "";
	        if (seconds != 0) {
	            var date = new Date();
	            date.setTime(date.getTime() + (seconds * 1000));
	            expires = "; expires=" + date.toGMTString()
	        }
	        document.cookie = name + "=" + escape(value) + expires + "; path=/"
	    },
	    getCookie: function(name) {
	        var nameEQ = name + "=";
	        var ca = document.cookie.split(';');
	        for (var i = 0; i < ca.length; i++) {
	            var c = ca[i];
	            while (c.charAt(0) == ' ') {
	                c = c.substring(1, c.length)
	            }
	            if (c.indexOf(nameEQ) == 0) {
	                return unescape(c.substring(nameEQ.length, c.length))
	            }
	        }
	        return false;
	    },
		/**
	     * 格式化金额
	     */
	    formatMoney: function(money) {
	        if (isNaN(money)) money = "0";
	        sign = (money == (money = Math.abs(money)));
	        money = money.toFixed(2);
	        cents = money.substring(money.indexOf("."));
	        money = Math.floor(money).toString();
	        for (var i = 0; i < Math.floor((money.length - (1 + i)) / 3); i++) {
	            money = money.substring(0, money.length - (4 * i + 3)) + ',' + money.substring(money.length - (4 * i + 3))
	        }
	        return (((sign) ? '': '-') + money + cents)
	    },
	    /**
	     * 格式化时间
	     * @param date
	     * @param pattern
	     * @returns
	     */
		format: function(date, pattern) {
	        this.date.setTime(date);
	        if (pattern == null || pattern == '') {
	            alert('格式化时间模板不能为空')
	        }
	        var time = pattern;
	        time = time.replace('yyyy', this.date.getFullYear());
	        time = time.replace('MM', this.date.getMonth() + 1 < 10 ? "0" + (this.date.getMonth() + 1) : (this.date.getMonth() + 1));
	        time = time.replace('dd', this.date.getDate() < 10 ? "0" + this.date.getDate() : this.date.getDate());
	        time = time.replace('HH', this.date.getHours() < 10 ? "0" + this.date.getHours() : this.date.getHours());
	        time = time.replace('mm', this.date.getMinutes() < 10 ? "0" + this.date.getMinutes() : this.date.getMinutes());
	        time = time.replace('ss', this.date.getSeconds() < 10 ? "0" + this.date.getSeconds() : this.date.getSeconds());
	        if (time.indexOf("hh") > -1) time = time.replace('hh', this.date.getHours() > 12 ? (this.date.getHours() - 12) + ".pm": (this.date.getHours() + ".am"));
	        
	        return time;
	    },
	    parser:function(dateStr, pattern){
	    	var date = new Date();
	    	if(!dateStr){
	    		return date;
	    	}
	    	var y_index = pattern.indexOf('yyyy');
	    	var y = y_index>-1?(dateStr.substring(y_index,y_index+4))*1:date.getFullYear();
	    	var M_index = pattern.indexOf('MM');
	    	var M = M_index>-1?(dateStr.substring(M_index,M_index+2)-1)*1:date.getMonth();
	    	var d_index = pattern.indexOf('dd');
	    	var d = d_index>-1?(dateStr.substring(d_index,d_index+2))*1:date.getDate();
	    	var H_index = pattern.indexOf('HH');
	    	var H = H_index>-1?(dateStr.substring(H_index,H_index+2))*1:date.getHours();
	    	var m_index = pattern.indexOf('mm');
	    	var m = m_index>-1?(dateStr.substring(m_index,m_index+2))*1:date.getMinutes();
	    	var s_index = pattern.indexOf('ss');
	    	var s = s_index>-1?(dateStr.substring(s_index,s_index+2))*1:date.getSeconds();
	    	
	    	return new Date(y, M, d, H, m, s, 0);
	    },
	    formForJson:function(form,arrKey){
	    	var formObj = document.getElementById(form);
	    	var obj = {};
	    	for(var i = 0 ;i<formObj.length;i++){
	    		var input = formObj[i];
	    		var name = input.attributes["name"];
	    		name = name?name.value:"";
	    		if(name.length>0){
	    			if(arrKey!=null && arrKey[name]){
	    				if(obj[name]==null){
	    					obj[name] = [];
	    				}
	    				obj[name].push(input.value);
	    			}else{
	    				if(obj[name]!=null){
		    				if(typeof obj=="object" && obj[name].constructor==Array){
		    					obj[name].push(obj[name]);
		    				}else{
		    					var tmp = [];
		    					tmp.push(obj[name]);
		    					tmp.push();
		    					obj[name] = tmp;
		    				}
		    			}else{
		    				obj[name] = input.value;
		    			}
	    			}
	    		}
	    	}
	    	return obj;
	    },
	    postJson:function(option){
	    	$.ajax({
	    		url:option.url,
	    		type:'post',
	    		contentType: "application/json; charset=utf-8",
	    		data:JSON.stringify(option.data),
	    		success:option.success
	    	});
	    }
};